﻿#region Copyright(C) 2018 FI Ltd. All rights reserved.
// ==================================================================================================
// Copyright(C) 2018 FI Ltd. All rights reserved.
//
// SYSTEM NAME      : FI.Net Application Framework
// COMPONENT ID     : FI.Core.EntLib
// COMPONENT DESC   : Microsoft Enterprise Library Adapter.
//
// CREATED DATE/BY  : 18 Dec 2018 / Tian Mi
//
// REVISION HISTORY :
// DATE/BY            SR#/CS/PM#/OTHERS       DESCRIPTION OF CHANGE
// ==================================================================================================
#endregion

using FI.Core.ExceptionHandling;
using FI.Core.IoC;
using System;
using Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration;
using FI.Core.Utilities;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;

namespace FI.Core.EntLib.ExceptionHandling
{
    [MapTo(typeof(IExceptionHandler), Lifetime = Lifetime.Singleton)]
    internal class DefaultExceptionHandler: IExceptionHandler
    {       
        public bool HandleException(Exception exceptionToHandle, string policyName, out Exception exceptionToThrow)
        {
            Guard.ArgumentNotNull(exceptionToHandle, "exceptionToHandle");
            Guard.ArgumentNotNullOrEmpty(policyName, "policyName");
            ExceptionHandlingSettings settings = ExceptionHandlingSettings.GetExceptionHandlingSettings(ConfigurationSourceFactory.Create());
            return settings.BuildExceptionManager().HandleException(exceptionToHandle, policyName, out exceptionToThrow);
        }
    }
}
